/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "hhdFile.h"
#include "hhdMacros.h"
#include "hhdInputStream.h"

namespace hhd
{
	class String;
	class InputStream;

	class FileInputStream : public InputStream
	{
		HHD_NO_CLASS_COPY(FileInputStream);
	public:
		/**
		* Open a File for reading ONLY.  A FileOutputStream cannot be opened on the same file.
		* @param in_path Location of file to open for reading.
		*/
		FileInputStream(const char8_t* in_path);
		FileInputStream(const String& in_path);
		~FileInputStream();

		/**
		* Closes and NULLs the underlying FILE*.  Subsequent calls on FileOutputStream will throw an exception.
		*/
		void close();

		/**
		* Reads a single character and returns as an int.  If there was an error reading, will return a negative integer.
		* If the stream is closed, will throw an exception.
		* @return The next char in the stream.
		*/
		bool read(char8_t& out_char);

		/**
		* Reads multiple bytes into a user provided buffer of at leaslt in_length size.  This method will return the number of
		* bytes actually read.
		* @param in_out_buffer Char array of at least length in_length.
		* @param in_length Number of bytes to read into the buffer.
		* @retutn The number of bytes actually read.
		*/
		bool read(char8_t* in_out_buffer, size_t in_length);

		/**
		* Resets the underslying FILE* to the beginning of the file as if you opened it for the first time.
		*/
		void reset();

		/**
		* Skips the passed in number of bytes from the current position in the stream.
		* @param in_bytes The number of bytes to skip.
		*/
		void skip(size_t in_bytes);

	private:
		File _file;
	};
}